package typejump.objects;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.util.LinkedList;

public class ObjectGroup extends GameObject {

	private LinkedList<GameObject> children = new LinkedList<GameObject>();
	
	@Override
	public boolean paintEnabled() {
		return true;
	}

	private Stroke stroke = new BasicStroke(2);
	@Override
	public void paint(Graphics2D g) {
		g.setColor(Color.YELLOW);
		Stroke k = g.getStroke();
		g.setStroke(stroke);
		for (GameObject go : children) {
			g.drawRect(go.ix(), go.iy(), go.iw(), go.ih());
		}
	}

	@Override
	public void update(double time) {

	}

	
	@Override
	public boolean intersects(GameObject other) {
		for (GameObject c : children) {
			if (c.intersects(other))
				return true;
		}
		return false;
	}
	
	public void add(GameObject object) {
		if (!children.contains(object))
			children.add(object);
	}
	public void remove(GameObject object) {
		children.remove(object);
	}
	public void clear() {
		children.clear();
	}
	
	public void deleteContents() {
		for (GameObject obj : children) {
			obj.remove();
		}
		clear();
	}
}
